public class Solution1694 {
    public String reformatNumber(String number) {
        number=number.replaceAll(" ","");
        number=number.replaceAll("-","");
        StringBuilder stringBuilder=new StringBuilder();
        while (number.length()>4){
            stringBuilder.append(number, 0, 3).append('-');
            number=number.substring(3);
        }
        if (number.length()<=3){
            stringBuilder.append(number);
        }else {
            stringBuilder.append(number, 0, 2).append('-').append(number.substring(2));
        }
        return stringBuilder.toString();
    }

    public static void main(String[] args) {
        System.out.println(new Solution1694().reformatNumber("1-23-45 6"));
    }
}
